home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’96 / PredatorPrey / calc_dork.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-06-22  |  49.4 KB  |  2,035 lines  |  [TEXT/KAHL]

  1.  
  2.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  3.             /*                                                               */
  4.             /*                    Prototype HP15C Calculator                */
  5.             /*                    James C. Ullrey                            */
  6.             /*                    INRESCO                                    */
  7.             /*                    © 1990                                    */
  8.             /*                    Version    13.97a                            */
  9.             /*                                                               */
  10.             /*                    DORK SEGMENT                               */
  11.             /*                                                               */
  12.             /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
  13.  
  14.  
  15. /*****************************************************************/
  16. /*  I N C L U D E S
  17. /*****************************************************************/
  18.  
  19. #ifndef __C14__
  20. #include    "PredatorPrey.h"
  21. #endif
  22. #include "calc_dork.h"
  23. #include "calc_update.h"
  24. #include "calc_draw_object.h"
  25. #include "calc_handlebutton.h"
  26.  
  27. /********************************************************************
  28. /*  G L O B A L   V A R I A B L E   D E C L A R A T I O N S
  29. /********************************************************************/
  30.  
  31. extern    WindowPtr    lastPtr;
  32. extern    Rect        gFirstCalcIcon,gSecondCalcIcon,gThirdCalcIcon;
  33. extern    Rect        gFourthCalcIcon,gFifthCalcIcon,gSixthCalcIcon;
  34. extern    WindowPtr    preyPtr;
  35.  
  36. /*****************************************************************/
  37. /*  P R O T O T Y P E S
  38. /*****************************************************************/
  39.  
  40.  
  41.         DialogPtr    GetStretchDialog    (void);
  42.         DialogPtr    GetRotateDialog        (void);
  43.         void        Do_Stretch            (WindowPtr wPtr);
  44.  
  45.         void        MatrixTimesVector    (
  46.                                             double_t transMat[4][4],
  47.                                             double_t *vector[]
  48.                                         );
  49.         void        MatTimesMat            (
  50.                                             double_t    rotMat[4][4],
  51.                                             double_t    oRotMat[4][4],
  52.                                             /*double    *rRotMat[4][4],*/
  53.                                             double_t    *qRotMat[]
  54.                                         );
  55.  
  56.         void        GetSinCos            (
  57.                                             double_t    delQ,
  58.                                             double_t    *sinQ,
  59.                                             double_t    *cosQ
  60.                                         );
  61.  
  62.  
  63. /*****************************************************************/
  64. /*****************************************************************/
  65. /*                                                                 */
  66. /* R O U T I N E S                                                 */
  67. /*                                                                 */
  68. /*****************************************************************/
  69. /*****************************************************************/
  70.  
  71. void    dork_seg() {}        /*  for reference in "UnloadSeg()" calls    */
  72.  
  73.  
  74. /*********************** GetStretchDialog ************************/
  75. DialogPtr    GetStretchDialog(void)
  76. {
  77.     DialogPtr    dPtr;
  78.     GrafPtr        oldPort;
  79.         
  80.     dPtr = GetNewDialog(BASE_RES_ID+20, NIL, (WindowPtr)-1L);
  81.     if(dPtr == NIL)
  82.     {
  83.         GetPort(&oldPort );
  84.         #ifdef      powerc
  85.             StopAlert(NO_STRETCH_DIALOG,    (UniversalProcPtr)NIL);
  86.         #else
  87.             StopAlert(NO_STRETCH_DIALOG,    NIL);
  88.         #endif      /* powerc */
  89.         SetPort( oldPort );
  90.         return(NIL);
  91.     }
  92.     return(dPtr);
  93. }
  94.  
  95. /*********************** GetRotateDialog *************************/
  96. DialogPtr    GetRotateDialog(void)
  97. {
  98.     DialogPtr    dPtr;
  99.     GrafPtr        oldPort;
  100.  
  101.     dPtr = GetNewDialog(BASE_RES_ID+25, NIL, (WindowPtr)-1L);
  102.     if(dPtr == NIL)
  103.     {
  104.         GetPort(&oldPort );
  105.         #ifdef      powerc
  106.             StopAlert(NO_ROTATE_DIALOG,    (UniversalProcPtr)NIL);
  107.         #else
  108.             StopAlert(NO_ROTATE_DIALOG,    NIL);
  109.         #endif      /* powerc */
  110.         SetPort( oldPort );
  111.         return(NIL);
  112.     }
  113.     return(dPtr);
  114. }
  115.  
  116. /*********************** HandleGraphChoice ***********************/
  117. /************************** Do_Stretch ***************************/
  118. void    Do_Stretch(WindowPtr wPtr)
  119. {
  120.     short        index,i,j;
  121.     long        inc;
  122.     long        ticktime;
  123.     WObjsHandle    w_objs_hndl;
  124.     objectDescr    the_object;
  125.     Boolean        spec;
  126.     
  127.     spec = FALSE;
  128.     
  129.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  130.     
  131.     for( index = 0; index < MAX_OBJECTS; index++)    
  132.     {
  133.         the_object = (**w_objs_hndl).object[index];
  134.         if((the_object.type == CUBE_OBJ) && (the_object.selected == TRUE))
  135.         {
  136.             for(i = 1;i <= 9; i++)
  137.             {
  138.                 switch(i)
  139.                 {
  140.                     case 1:
  141.                     case 9:
  142.                         inc = 1;
  143.                         break;
  144.                     case 2:
  145.                     case 8:
  146.                         inc = 2;
  147.                         break;
  148.                     case 3:
  149.                     case 7:
  150.                         inc = 4;
  151.                         break;
  152.                     case 4:
  153.                     case 6:
  154.                         inc = 8;
  155.                         break;
  156.                     case 5:
  157.                         inc = 10;
  158.                         break;
  159.                         
  160.                 }
  161.                 for(j = 0; j<=7; j++)
  162.                 {
  163.                     switch(j)
  164.                     {
  165.                         case 1:
  166.                         case 2:
  167.                         case 5:
  168.                         case 6:
  169.                             (**w_objs_hndl).object[index]._3dPt[j].x_point += inc;
  170.                             break;
  171.                         case 0:
  172.                         case 3:
  173.                         case 4:
  174.                         case 7:
  175.                             (**w_objs_hndl).object[index]._3dPt[j].x_point -= inc;
  176.                             break;
  177.                     }
  178.                 }
  179.                 EraseRect(&(**w_objs_hndl).object[index].bounds);
  180.                 SetRect(&(**w_objs_hndl).object[index].bounds,
  181.                             (**w_objs_hndl).object[index].bounds.left - (inc /*+ 1*/),
  182.                             (**w_objs_hndl).object[index].bounds.top,
  183.                             (**w_objs_hndl).object[index].bounds.right + (inc /*+ 1*/),
  184.                             (**w_objs_hndl).object[index].bounds.bottom);
  185.                 
  186.                 /*SetRect(&(**w_objs_hndl).object[index].bounds,+(inc+1),0);*/
  187.                 draw_object(wPtr,index, spec);
  188.                 Delay (60L, &ticktime);
  189.             }
  190.         }    
  191.     }
  192. }
  193.  
  194.  
  195. /************************** Do_Rotate ****************************/
  196. void    Do_Rotate(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
  197.                          /* when coming from a mouseclick in */
  198.                         /* gRotateBox, wPtr is LastPtr    */
  199. {
  200.     Boolean        spec;
  201.     Point        offset;
  202.     Rect        obj_rect;
  203.     short        myItemHit;
  204.     short        index;
  205.     short        i,j,k;
  206.     short        limit;
  207.     short        resultRow;
  208.     short        resultCol;
  209.     short        sourceCol;
  210.     short        yBase;
  211.     short        xBase;
  212.     short        zBase;
  213.     short        yNum;
  214.     short        xNum;
  215.     short        zNum;
  216.     
  217.     long        minX,maxX,minY,maxY,minZ,maxZ;
  218.     long        tempX,tempY,tempZ;
  219.     long        newX,newY,newZ;
  220.     WObjsHandle    w_objs_hndl;
  221.     objectDescr    the_object;
  222.     
  223.     double_t    transMat[4][4];
  224.     double_t    rotMat[4][4];        
  225.     double_t    rRotMat[4][4];    
  226.     
  227.     double_t    vector[4];
  228.     double_t    newVect[4];
  229.     
  230.     double_t    sinX,cosX,sinY,cosY,sinZ,cosZ;
  231.     
  232.     GrafPtr        oldPort;
  233.     Boolean        notFront;
  234.     
  235.     for(i = 0;i <= 3;i++)
  236.     {
  237.         for(j = 0;j <= 3;j++)
  238.         {
  239.             if(i == j)
  240.             {
  241.                 transMat[i][j] = 1;
  242.                 rotMat[i][j] = 1;
  243.             }
  244.             else
  245.             {
  246.                 transMat[i][j] = 0;
  247.                 rotMat[i][j] = 0;
  248.             }
  249.         }
  250.     }
  251.     vector[3] = 1;
  252.     
  253.     if(delX == 0 && delY == 0 && delZ == 0)
  254.     {
  255.         return;
  256.     }
  257.     
  258.     if(delX != 0)
  259.     {
  260.         GetSinCos(delX,&sinX,&cosX);
  261.         rotMat[1][1] = cosX;
  262.         rotMat[1][2] = sinX;
  263.         rotMat[2][1] = -sinX;
  264.         rotMat[2][2] = cosX;
  265.     }
  266.     else if(delY != 0)
  267.     {
  268.         GetSinCos(delY,&sinY,&cosY);
  269.         rotMat[0][0] = cosY;
  270.         rotMat[0][2] = sinY;
  271.         rotMat[2][0] = -sinY;
  272.         rotMat[2][2] = cosY;
  273.     }
  274.     else if(delZ != 0)
  275.     {
  276.         GetSinCos(delZ,&sinZ,&cosZ);
  277.         rotMat[0][0] = cosZ;
  278.         rotMat[0][1] = sinZ;
  279.         rotMat[1][0] = -sinZ;
  280.         rotMat[1][1] = cosZ;
  281.     }
  282.     
  283.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  284.     
  285.     for( index = 0; index < MAX_OBJECTS; index++)    
  286.     {
  287.         the_object = (**w_objs_hndl).object[index];
  288.         if(((the_object.type == CUBE_OBJ) || (the_object.type == HOUSE_OBJ)) && (the_object.selected == TRUE))
  289.         {
  290.             minZ = (**w_objs_hndl).object[index]._3dPt[0].z_point;
  291.             maxZ = (**w_objs_hndl).object[index]._3dPt[0].z_point;
  292.             switch(the_object.type)
  293.             {
  294.                 case 4:
  295.                     limit = 7;
  296.                     break;
  297.                 case 5:
  298.                     if((**w_objs_hndl).object[index].armed == TRUE)    limit = 21;
  299.                     else    limit = 17;
  300.                     break;
  301.             }
  302.             for(i = 1; i <= limit; i++)
  303.             {
  304.                 tempZ = (**w_objs_hndl).object[index]._3dPt[i].z_point;
  305.                 if(tempZ < minZ)
  306.                 {
  307.                     minZ = tempZ;
  308.                 }
  309.                 if(tempZ > maxZ)
  310.                 {
  311.                     maxZ = tempZ;
  312.                 }
  313.             }
  314.             minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
  315.             maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
  316.             minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
  317.             maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
  318.             
  319.             newX = minX + (maxX - minX)/2;        /*    X-midpoint    */
  320.             newY = minY + (maxY - minY)/2;        /*    Y-midpoint    */
  321.             newZ = minZ + (maxZ - minZ)/2;        /*    Z-midpoint    */
  322.             
  323.             if(delX != 0)
  324.             {
  325.                 rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
  326.                 rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
  327.             }
  328.             else if(delY != 0)
  329.             {
  330.                 rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
  331.                 rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
  332.             }
  333.             else if(delZ != 0)
  334.             {
  335.                 rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
  336.                 rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
  337.             }
  338.             
  339.             for(i = 0;i <= 3;i++)        /* initialize rRotMat */
  340.             {
  341.                 for(j = 0;j <= 3;j++)
  342.                 {
  343.                     rRotMat[i][j] = 0;
  344.                 }
  345.             }
  346.  
  347.             for(i = 0;i <= 3;i++)
  348.             {
  349.                 for(j = 0;j <= 3;j++)
  350.                 {
  351.                     for(k = 0;k <= 3;k++)
  352.                     {
  353.                         rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).object[index].rotHist[k][j].rotElem;
  354.                     }
  355.                 }
  356.             }
  357.             for(i = 0;i <= 3;i++)        /* update rotHist */
  358.             {
  359.                 for(j = 0;j <= 3;j++)
  360.                 {
  361.                     (**w_objs_hndl).object[index].rotHist[i][j].rotElem = rRotMat[i][j];
  362.                 }
  363.             }
  364.             /*********************** update _3dPt[i] ***********************/
  365.             for(i = 0; i <= limit; i++)
  366.             {
  367.                 vector[0] = (**w_objs_hndl).object[index]._3dPtH[i].x_point;
  368.                 vector[1] = (**w_objs_hndl).object[index]._3dPtH[i].y_point;
  369.                 vector[2] = (**w_objs_hndl).object[index]._3dPtH[i].z_point;
  370.  
  371.  
  372.  
  373.                 for(j = 0;j<=3;j++)
  374.                 {
  375.                     newVect[j] = 0;
  376.                 }
  377.                 for(j = 0;j <= 3;j++)    /*    row of matrix    */
  378.                 {
  379.                     for(k = 0;k <= 3;k++)
  380.                     {
  381.                         newVect[j] += (**w_objs_hndl).object[index].rotHist[j][k].rotElem * vector[k];
  382.                     }
  383.                 }
  384.                 for(j = 0;j<=3;j++)
  385.                 {
  386.                     vector[j] = newVect[j];
  387.                 }
  388.                 (**w_objs_hndl).object[index]._3dPt[i].x_point = ceil(vector[0]);
  389.                 (**w_objs_hndl).object[index]._3dPt[i].y_point = ceil(vector[1]);
  390.                 (**w_objs_hndl).object[index]._3dPt[i].z_point = ceil(vector[2]);
  391.             }
  392.             
  393.             /******************* end of update _3dPt[i] ********************/
  394.  
  395.             if(FrontWindow() != lastPtr)
  396.             {
  397.                 GetPort(&oldPort);
  398.                 SetPort(lastPtr);
  399.                 notFront = TRUE;
  400.             }
  401.             offset = (**w_objs_hndl).scrollAmount;
  402.             obj_rect = (**w_objs_hndl).object[index].bounds;
  403.             OffsetRect(&obj_rect, -offset.h, -offset.v);
  404.                         
  405.             EraseRect(&obj_rect);
  406.             InvalRect(&obj_rect);
  407.             minX = (**w_objs_hndl).object[index]._3dPt[0].x_point;    /* both are longs    */
  408.             maxX = (**w_objs_hndl).object[index]._3dPt[0].x_point;
  409.             minY = (**w_objs_hndl).object[index]._3dPt[0].y_point;
  410.             maxY = (**w_objs_hndl).object[index]._3dPt[0].y_point;
  411. /*            switch(the_object.type)*/
  412. /*            {*/
  413. /*                case 4:*/
  414. /*                    limit = 7;*/
  415. /*                    break;*/
  416. /*                case 5:*/
  417. /*                    limit = 17;*/
  418. /*                    break;*/
  419. /*            }*/
  420.  
  421.             for(i = 1; i <= limit; i++)
  422.             {
  423.                 tempX = (**w_objs_hndl).object[index]._3dPt[i].x_point;
  424.                 tempY = (**w_objs_hndl).object[index]._3dPt[i].y_point;
  425.                 if(tempX < minX)
  426.                 {
  427.                     minX = tempX;
  428.                 }
  429.                 if(tempX > maxX)
  430.                 {
  431.                     maxX = tempX;
  432.                 }
  433.                 if(tempY < minY)
  434.                 {
  435.                     minY = tempY;
  436.                 }
  437.                 if(tempY > maxY)
  438.                 {
  439.                     maxY = tempY;
  440.                 }
  441.             }
  442.             SetRect(&(**w_objs_hndl).object[index].bounds,minX,minY,maxX+1,maxY+1);
  443.             InvalRect(&(**w_objs_hndl).object[index].bounds);
  444.             if(notFront)
  445.             {
  446.                 SetPort(oldPort);
  447.                 notFront = FALSE;
  448.             }
  449.             /***************** experimental modification *****************/
  450.             /*draw_object(wPtr,index);*/
  451.             do_update(wPtr);
  452.             /*do_spec_update(wPtr,index);*/
  453.             /************** end of experimental modification *************/                
  454.         }
  455.     }
  456. }
  457.  
  458. /************************* Do_Movement ***************************/
  459. void    Do_Movement(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
  460.                          /* when coming from a mouseclick in */
  461.                         /* gRotateBox, wPtr is LastPtr    */
  462. {
  463.     Boolean        spec;
  464.     Point        offset;
  465.     Rect        obj_rect;
  466.     short        myItemHit;
  467.     short        index;
  468.     short        i,j,k,n;
  469.     short        limit,obj_limit;
  470.     short        resultRow;
  471.     short        resultCol;
  472.     short        sourceCol;
  473.     short        yBase;
  474.     short        xBase;
  475.     short        zBase;
  476.     short        yNum;
  477.     short        xNum;
  478.     short        zNum;
  479.     short        _left,_top,_right,_bottom;
  480.     
  481.     long        minX,maxX,minY,maxY,minZ,maxZ;
  482.     long        tempX,tempY,tempZ;
  483.     long        newX,newY,newZ;
  484.     WObjsHandle    w_objs_hndl;
  485.     objectDescr    the_object;
  486.     
  487.     double_t    transMat[4][4];
  488.     double_t    rotMat[4][4];        
  489.     double_t    rRotMat[4][4];    
  490.     
  491.     double_t    vector[4];
  492.     double_t    newVect[4];
  493.     
  494.     double_t    sinX,cosX,sinY,cosY,sinZ,cosZ;
  495.     
  496.     GrafPtr        oldPort;
  497.     Boolean        notFront;
  498.     
  499.     if(FrontWindow() != lastPtr)
  500.     {
  501.         GetPort(&oldPort);
  502.         SetPort(lastPtr);
  503.         InvalRect(&lastPtr->portRect);
  504.         notFront = TRUE;
  505.     }
  506.     else    InvalRect(&lastPtr->portRect);
  507.     
  508.     for(i = 0;i <= 3;i++)
  509.     {
  510.         for(j = 0;j <= 3;j++)
  511.         {
  512.             if(i == j)
  513.             {
  514.                 transMat[i][j] = 1;
  515.                 rotMat[i][j] = 1;
  516.             }
  517.             else
  518.             {
  519.                 transMat[i][j] = 0;
  520.                 rotMat[i][j] = 0;
  521.             }
  522.         }
  523.     }
  524.     vector[3] = 1;
  525.     
  526.     if(delX == 0 && delY == 0 && delZ == 0)
  527.     {
  528.         return;
  529.     }
  530.     
  531.     if(delX != 0)
  532.     {
  533.         GetSinCos(delX,&sinX,&cosX);
  534.         rotMat[1][1] = cosX;
  535.         rotMat[1][2] = sinX;
  536.         rotMat[2][1] = -sinX;
  537.         rotMat[2][2] = cosX;
  538.     }
  539.     else if(delY != 0)
  540.     {
  541. //#ifdef testPrey
  542. //    delY = -180;
  543. //#endif        
  544.         GetSinCos(delY,&sinY,&cosY);
  545.         rotMat[0][0] = cosY;
  546.         rotMat[0][2] = sinY;
  547.         rotMat[2][0] = -sinY;
  548.         rotMat[2][2] = cosY;
  549.     }
  550.     else if(delZ != 0)
  551.     {
  552.         GetSinCos(delZ,&sinZ,&cosZ);
  553.         rotMat[0][0] = cosZ;
  554.         rotMat[0][1] = sinZ;
  555.         rotMat[1][0] = -sinZ;
  556.         rotMat[1][1] = cosZ;
  557.     }
  558.     
  559.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  560.     
  561.     HLock((Handle)w_objs_hndl);
  562.     
  563.     /* *---------------------------------------- long            */
  564.     /* |                                *------- long            */
  565.     /* |                                |                        */
  566.     /* v                                v                        */
  567.     newX =     (**w_objs_hndl).gXYZplane.x_point;        //minX + (maxX - minX)/2;
  568.     newY =     (**w_objs_hndl).gXYZplane.y_point;        //minY + (maxY - minY)/2;
  569.     newZ =     (**w_objs_hndl).gXYZplane.z_point;        //minZ + (maxZ - minZ)/2;
  570.     (**w_objs_hndl).gXYZplane.no_point = 1;    /*    this may be redundant    */
  571.     
  572.  
  573. /********    don't bother    *****************
  574.  
  575.     for(n = 0;n <= 15;n++)
  576.     {
  577.         minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  578.         maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  579.         minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  580.         maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  581.         minZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
  582.         maxZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
  583.         
  584.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  585.         
  586.         for(i = 1; i < limit; i++)
  587.         {
  588.             tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
  589.             tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  590.             tempZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point;
  591.             if(tempX < minX)
  592.             {
  593.                 minX = tempX;
  594.             }
  595.             if(tempX > maxX)
  596.             {
  597.                 maxX = tempX;
  598.             }
  599.             if(tempY < minY)
  600.             {
  601.                 minY = tempY;
  602.             }
  603.             if(tempY > maxY)
  604.             {
  605.                 maxY = tempY;
  606.             }
  607.             if(tempZ < minZ)
  608.             {
  609.                 minZ = tempZ;
  610.             }
  611.             if(tempZ > maxZ)
  612.             {
  613.                 maxZ = tempZ;
  614.             }
  615.         }
  616.         SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
  617.         InvalRect(&(**w_objs_hndl).bg_object[n].bounds);    
  618.         EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  619.     }
  620.     
  621.     ************    end of don't bother    ************/
  622.     
  623.     if((**w_objs_hndl).hasTargets == TRUE)
  624.     {
  625.         obj_limit = 21;
  626.         
  627.         /************
  628.         
  629.         for(n = 16;n <= 21;n++)
  630.         {
  631.             _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  632.             _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  633.             _right = _left + 32;
  634.             _bottom = _top + 32;
  635.             SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
  636.             InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  637.             EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  638.         }
  639.         
  640.         ******************/
  641.     }
  642.     else    obj_limit = 15;
  643.  
  644.  
  645.  
  646.     //minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
  647.     //maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
  648.     //minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
  649.     //maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
  650.     
  651.     HUnlock((Handle)w_objs_hndl);
  652.     
  653.     if(delX != 0)
  654.     {
  655.         rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
  656.         rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
  657.     }
  658.     else if(delY != 0)
  659.     {
  660.         rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
  661.         rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
  662.     }
  663.     else if(delZ != 0)
  664.     {
  665.         rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
  666.         rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
  667.     }
  668.  
  669.  
  670.     for(n = 0;n <= obj_limit;n++)
  671.     {
  672.         for(i = 0;i <= 3;i++)        /* initialize rRotMat */
  673.         {
  674.             for(j = 0;j <= 3;j++)
  675.             {
  676.                 rRotMat[i][j] = 0;
  677.             }
  678.         }
  679.         for(i = 0;i <= 3;i++)
  680.         {
  681.             for(j = 0;j <= 3;j++)
  682.             {
  683.                 for(k = 0;k <= 3;k++)
  684.                 {
  685.                     rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).bg_object[n].rotHist[k][j].rotElem;
  686.                 }
  687.             }
  688.         }
  689.         for(i = 0;i <= 3;i++)        /* update rotHist */
  690.         {
  691.             for(j = 0;j <= 3;j++)
  692.             {
  693.                 (**w_objs_hndl).bg_object[n].rotHist[i][j].rotElem = rRotMat[i][j];
  694.             }
  695.         }
  696.     }
  697.  
  698.     /*********************** update _3dPt[i] ***********************/
  699.     for(n = 0;n <= obj_limit;n++)
  700.     {
  701.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  702.         
  703.         for(i = 0; i < limit; i++)
  704.         {
  705.             vector[0] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].x_point;
  706.             vector[1] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].y_point;
  707.             vector[2] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].z_point;
  708.     
  709.     
  710.     
  711.             for(j = 0;j <= 3;j++)
  712.             {
  713.                 newVect[j] = 0;
  714.             }
  715.             for(j = 0;j <= 3;j++)    /*    row of matrix    */
  716.             {
  717.                 for(k = 0;k <= 3;k++)
  718.                 {
  719.                     newVect[j] += (**w_objs_hndl).bg_object[n].rotHist[j][k].rotElem * vector[k];
  720.                 }
  721.             }
  722.             for(j = 0;j <= 3;j++)
  723.             {
  724.                 vector[j] = newVect[j];
  725.             }
  726.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point = ceil(vector[0]);
  727.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point = ceil(vector[1]);
  728.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point = ceil(vector[2]);
  729.         }
  730.     }    
  731.     /******************* end of update _3dPt[i] ********************/
  732.  
  733.     offset = (**w_objs_hndl).scrollAmount;
  734.     //obj_rect = (**w_objs_hndl).object[index].bounds;
  735.     //OffsetRect(&obj_rect, -offset.h, -offset.v);
  736.                 
  737.     //EraseRect(&obj_rect);
  738.     //InvalRect(&obj_rect);
  739.     
  740.     /***********************
  741.     
  742.     for(n = 0;n <= 15;n++)
  743.     {
  744.         minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  745.         maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  746.         minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  747.         maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  748.  
  749.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  750.         
  751.         for(i = 1; i < limit; i++)
  752.         {
  753.             tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
  754.             tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  755.             if(tempX < minX)
  756.             {
  757.                 minX = tempX;
  758.             }
  759.             if(tempX > maxX)
  760.             {
  761.                 maxX = tempX;
  762.             }
  763.             if(tempY < minY)
  764.             {
  765.                 minY = tempY;
  766.             }
  767.             if(tempY > maxY)
  768.             {
  769.                 maxY = tempY;
  770.             }
  771.         }
  772.         SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
  773.         //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  774.         //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);     why doing this again?    
  775.     }
  776.     
  777.  
  778.     
  779.     if((**w_objs_hndl).hasTargets == TRUE)
  780.     {
  781.         for(n = 16;n <= 21;n++)
  782.         {
  783.             _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  784.             _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  785.             _right = _left + 32;
  786.             _bottom = _top + 32;
  787.             SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
  788.             //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  789.             //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);        seems to be erasing the place to where the new position is to be drawn
  790.         }
  791.     }
  792.     
  793.     *******************/    
  794.     
  795.     if(notFront)
  796.     {
  797.         SetPort(oldPort);
  798.         notFront = FALSE;
  799.     }
  800.     /***************** experimental modification *****************/
  801.     /*draw_object(wPtr,index);*/
  802.     do_update(wPtr);                    /*    in calc_update.c    */
  803.     /*do_spec_update(wPtr,index);*/
  804.     /************** end of experimental modification *************/    
  805. }
  806.  
  807. /************************ Do_Translation *************************/
  808. void    Do_Translation(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
  809.                          /* when coming from a mouseclick in */
  810.                         /* gRotateBox, wPtr is LastPtr    */
  811. {
  812.     short        i,n;
  813.     short        limit;
  814.     long        minX,maxX,minY,maxY,minZ,maxZ;
  815.     long        tempX,tempY,tempZ;
  816.     WObjsHandle    w_objs_hndl;
  817.     objectDescr    the_object;
  818.     GrafPtr        oldPort;
  819.     Boolean        notFront;
  820.  
  821.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  822.     
  823.         
  824.     if(FrontWindow() != lastPtr)
  825.     {
  826.         GetPort(&oldPort);
  827.         SetPort(lastPtr);
  828.         InvalRect(&lastPtr->portRect);
  829.         notFront = TRUE;
  830.     }
  831.     else    InvalRect(&lastPtr->portRect);
  832.     /**************************************
  833.     
  834.     
  835.     for(n = 0;n <= 15;n++)
  836.     {
  837.  
  838.         minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  839.         maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  840.         minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  841.         maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  842.  
  843.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  844.     
  845.         for(i = 1; i < limit; i++)
  846.         {
  847.             tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;    /*    both longs    *//*
  848.             tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  849.             
  850.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point += delZ;
  851.             
  852.             if(tempX < minX)
  853.             {
  854.                 minX = tempX;
  855.             }
  856.             if(tempX > maxX)
  857.             {
  858.                 maxX = tempX;
  859.             }
  860.             if(tempY < minY)
  861.             {
  862.                 minY = tempY;
  863.             }
  864.             if(tempY > maxY)
  865.             {
  866.                 maxY = tempY;
  867.             }
  868.         }
  869.         SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
  870.         InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  871.         EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  872.     }    
  873.     
  874.     **************/
  875.  
  876. /*************************************************************************    
  877.  
  878.  
  879.     minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  880.     maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  881.     minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  882.     maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  883.  
  884.     for(i = 1; i < limit; i++)
  885.     {
  886.         tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
  887.         tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  888.         if(tempX < minX)
  889.         {
  890.             minX = tempX;
  891.         }
  892.         if(tempX > maxX)
  893.         {
  894.             maxX = tempX;
  895.         }
  896.         if(tempY < minY)
  897.         {
  898.             minY = tempY;
  899.         }
  900.         if(tempY > maxY)
  901.         {
  902.             maxY = tempY;
  903.         }
  904.     }
  905.     SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
  906.     EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  907.     InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  908. *************************************************************************/    
  909.     if(notFront)
  910.     {
  911.         SetPort(oldPort);
  912.         notFront = FALSE;
  913.     }
  914.     /***************** experimental modification *****************/
  915.     /*draw_object(wPtr,index);*/
  916.     do_update(wPtr);
  917.     /*do_spec_update(wPtr,index);*/
  918.     /************** end of experimental modification *************/    
  919. }
  920.  
  921. /*********************** Do_Plane_Control ************************/
  922. void    Do_Plane_Control(WindowPtr wPtr,double_t delX,double_t delY,double_t delZ,Boolean useCalc)
  923. {
  924. Boolean        spec;
  925.     Point        offset;
  926.     Rect        obj_rect;
  927.     short        myItemHit;
  928.     short        index;
  929.     short        i,j,k,n;
  930.     short        limit,obj_limit;
  931.     short        resultRow;
  932.     short        resultCol;
  933.     short        sourceCol;
  934.     short        yBase;
  935.     short        xBase;
  936.     short        zBase;
  937.     short        yNum;
  938.     short        xNum;
  939.     short        zNum;
  940.     short        _left,_top,_right,_bottom;
  941.     short        houseN;
  942.     
  943.     long        minX,maxX,minY,maxY,minZ,maxZ;
  944.     long        tempX,tempY,tempZ;
  945.     long        newX,newY,newZ;
  946.     WObjsHandle    w_objs_hndl;
  947.     objectDescr    the_object;
  948.     
  949.     double_t    transMat[4][4];
  950.     double_t    rotMat[4][4];        
  951.     double_t    rRotMat[4][4];    
  952.     
  953.     double_t    vector[4];
  954.     double_t    newVect[4];
  955.     
  956.     double_t    sinX,cosX,sinY,cosY,sinZ,cosZ;
  957.     
  958.     GrafPtr        oldPort;
  959.     Boolean        notFront;
  960.     
  961.     w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  962.     if((**w_objs_hndl).isPrey == 1)
  963.     {
  964.         if(preyPtr != NIL)
  965.         {
  966.             if(FrontWindow() != preyPtr)
  967.             {
  968.                 GetPort(&oldPort);
  969.                 SetPort(preyPtr);
  970.                 InvalRect(&preyPtr->portRect);
  971.                 notFront = TRUE;
  972.             }
  973.             else
  974.             {
  975.                 InvalRect(&preyPtr->portRect);
  976.                 notFront = FALSE;
  977.             }
  978.         }
  979.         else
  980.         {
  981.             GetPort(&oldPort);
  982.             SetPort(wPtr);
  983.             InvalRect(&wPtr->portRect);
  984.         }    
  985.     }
  986.     else
  987.     {
  988.         if(FrontWindow() != lastPtr)
  989.         {
  990.             GetPort(&oldPort);
  991.             SetPort(lastPtr);
  992.             InvalRect(&lastPtr->portRect);
  993.             notFront = TRUE;
  994.         }
  995.         else
  996.         {
  997.             InvalRect(&lastPtr->portRect);
  998.             notFront = FALSE;
  999.         }
  1000.     }
  1001.     for(i = 0;i <= 3;i++)    /*    initialize transMat & rotMat    */
  1002.     {
  1003.         for(j = 0;j <= 3;j++)
  1004.         {
  1005.             if(i == j)
  1006.             {
  1007.                 transMat[i][j] = 1;
  1008.                 rotMat[i][j] = 1;
  1009.             }
  1010.             else
  1011.             {
  1012.                 transMat[i][j] = 0;
  1013.                 rotMat[i][j] = 0;
  1014.             }
  1015.         }
  1016.     }
  1017.     vector[3] = 1;
  1018.     
  1019.     if(delX == 0 && delY == 0 && delZ == 0)
  1020.     {
  1021.         return;
  1022.     }
  1023.     
  1024.     if(delX != 0)
  1025.     {
  1026.         GetSinCos(delX,&sinX,&cosX);
  1027.         rotMat[1][1] = cosX;
  1028.         rotMat[1][2] = sinX;
  1029.         rotMat[2][1] = -sinX;
  1030.         rotMat[2][2] = cosX;
  1031.     }
  1032.     else if(delY != 0)
  1033.     {
  1034.         GetSinCos(delY,&sinY,&cosY);
  1035.         rotMat[0][0] = cosY;
  1036.         rotMat[0][2] = sinY;
  1037.         rotMat[2][0] = -sinY;
  1038.         rotMat[2][2] = cosY;
  1039.     }
  1040.     else if(delZ != 0)
  1041.     {
  1042.         GetSinCos(delZ,&sinZ,&cosZ);
  1043.         rotMat[0][0] = cosZ;
  1044.         rotMat[0][1] = sinZ;
  1045.         rotMat[1][0] = -sinZ;
  1046.         rotMat[1][1] = cosZ;
  1047.     }
  1048.     
  1049.     //w_objs_hndl = (WObjsHandle)GetWRefCon(wPtr);
  1050.     
  1051.     HLock((Handle)w_objs_hndl);
  1052.     
  1053.     n = 0;
  1054.     while((**w_objs_hndl).object[n].armed == FALSE) n++;
  1055.     
  1056.  
  1057.     newX = (**w_objs_hndl).object[n]._3dPtH[7].x_point;        //minX + (maxX - minX)/2;
  1058.     newY = (**w_objs_hndl).object[n]._3dPtH[7].y_point;        //minY + (maxY - minY)/2;
  1059.     newZ = -100;                                            //minZ + (maxZ - minZ)/2;
  1060.     (**w_objs_hndl).gXYZplane.no_point = 1;
  1061.     houseN = n;
  1062.     /********************************
  1063.  
  1064.  
  1065.     for(n = 0;n <= 15;n++)
  1066.     {
  1067.         minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1068.         maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1069.         minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1070.         maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1071.         minZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
  1072.         maxZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].z_point;
  1073.         
  1074.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  1075.         
  1076.         for(i = 1; i < limit; i++)
  1077.         {
  1078.             tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
  1079.             tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  1080.             tempZ = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point;
  1081.             if(tempX < minX)
  1082.             {
  1083.                 minX = tempX;
  1084.             }
  1085.             if(tempX > maxX)
  1086.             {
  1087.                 maxX = tempX;
  1088.             }
  1089.             if(tempY < minY)
  1090.             {
  1091.                 minY = tempY;
  1092.             }
  1093.             if(tempY > maxY)
  1094.             {
  1095.                 maxY = tempY;
  1096.             }
  1097.             if(tempZ < minZ)
  1098.             {
  1099.                 minZ = tempZ;
  1100.             }
  1101.             if(tempZ > maxZ)
  1102.             {
  1103.                 maxZ = tempZ;
  1104.             }
  1105.         }
  1106.         SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX-1,minY-1,maxX+1,maxY+1);
  1107.         InvalRect(&(**w_objs_hndl).bg_object[n].bounds);    
  1108.         EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  1109.     }
  1110.     
  1111.     *********************/
  1112.     
  1113.     
  1114.     if((**w_objs_hndl).hasTargets == TRUE)
  1115.     {
  1116.         obj_limit = 21;
  1117.         /*****************
  1118.         
  1119.         for(n = 16;n <= 21;n++)
  1120.         {
  1121.             _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1122.             _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1123.             _right = _left + 32;
  1124.             _bottom = _top + 32;
  1125.             SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
  1126.             InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  1127.             EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  1128.         }
  1129.         
  1130.         ***************/
  1131.         
  1132.     }
  1133.     else    obj_limit = 15;
  1134.  
  1135.  
  1136.  
  1137.     //minX = (**w_objs_hndl).object[index].bounds.left/* - offset.h*/;
  1138.     //maxX = (**w_objs_hndl).object[index].bounds.right/* - offset.h*/;
  1139.     //minY = (**w_objs_hndl).object[index].bounds.top/* - offset.v*/;
  1140.     //maxY = (**w_objs_hndl).object[index].bounds.bottom/* - offset.v*/;
  1141.     
  1142.     HUnlock((Handle)w_objs_hndl);
  1143.     
  1144.     if(delX != 0)
  1145.     {
  1146.         rotMat[1][3] = newY * (1 - cosX) - newZ * sinX;
  1147.         rotMat[2][3] = newZ * (1 - cosX) + newY * sinX;
  1148.     }
  1149.     else if(delY != 0)
  1150.     {
  1151.         rotMat[0][3] = newX * (1 - cosY) - newZ * sinY;
  1152.         rotMat[2][3] = newZ * (1 - cosY) + newX * sinY;
  1153.     }
  1154.     else if(delZ != 0)
  1155.     {
  1156.         rotMat[0][3] = newX * (1 - cosZ) - newY * sinZ;
  1157.         rotMat[1][3] = newY * (1 - cosZ) + newX * sinZ;
  1158.     }
  1159.  
  1160.  
  1161.     for(n = 0;n <= obj_limit;n++)
  1162.     {
  1163.         for(i = 0;i <= 3;i++)        /* initialize rRotMat */
  1164.         {
  1165.             for(j = 0;j <= 3;j++)
  1166.             {
  1167.                 rRotMat[i][j] = 0;
  1168.             }
  1169.         }
  1170.         for(i = 0;i <= 3;i++)
  1171.         {
  1172.             for(j = 0;j <= 3;j++)
  1173.             {
  1174.                 for(k = 0;k <= 3;k++)
  1175.                 {
  1176.                     rRotMat[i][j] += rotMat[i][k] * (**w_objs_hndl).bg_object[n].rotHist[k][j].rotElem;
  1177.                 }
  1178.             }
  1179.         }
  1180.         for(i = 0;i <= 3;i++)        /* update rotHist */
  1181.         {
  1182.             for(j = 0;j <= 3;j++)
  1183.             {
  1184.                 (**w_objs_hndl).bg_object[n].rotHist[i][j].rotElem = rRotMat[i][j];
  1185.             }
  1186.         }
  1187.     }
  1188.     
  1189.     if((**w_objs_hndl).isPrey == 1)
  1190.     {
  1191.         n = houseN;
  1192.         for(i = 0; i < 21; i++)
  1193.         {
  1194.             vector[0] = (**w_objs_hndl).object[n]._3dPtH[i].x_point;
  1195.             vector[1] = (**w_objs_hndl).object[n]._3dPtH[i].y_point;
  1196.             vector[2] = (**w_objs_hndl).object[n]._3dPtH[i].z_point;
  1197.             
  1198.             for(j = 0;j <= 3;j++)
  1199.             {
  1200.                 newVect[j] = 0;
  1201.             }
  1202.  
  1203.             for(j = 0;j <= 3;j++)    /*    row of matrix    */
  1204.             {
  1205.                 for(k = 0;k <= 3;k++)
  1206.                 {
  1207.                     newVect[j] += (**w_objs_hndl).object[n].rotHist[j][k].rotElem * vector[k];
  1208.                 }
  1209.             }
  1210.             
  1211.             for(j = 0;j <= 3;j++)
  1212.             {
  1213.                 vector[j] = newVect[j];
  1214.             }
  1215.             (**w_objs_hndl).object[n]._3dPt[i].x_point = ceil(vector[0]);
  1216.             (**w_objs_hndl).object[n]._3dPt[i].y_point = ceil(vector[1]);
  1217.             (**w_objs_hndl).object[n]._3dPt[i].z_point = ceil(vector[2]);
  1218.         }
  1219.     }
  1220.     /*********************** update _3dPt[i] ***********************/
  1221.     for(n = 0;n <= obj_limit;n++)
  1222.     {
  1223.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  1224.         
  1225.         for(i = 0; i < limit; i++)
  1226.         {
  1227.             vector[0] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].x_point;
  1228.             vector[1] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].y_point;
  1229.             vector[2] = (**w_objs_hndl).bg_object[n]._3dPtH_BG[i].z_point;
  1230.     
  1231.     
  1232.     
  1233.             for(j = 0;j <= 3;j++)
  1234.             {
  1235.                 newVect[j] = 0;
  1236.             }
  1237.             for(j = 0;j <= 3;j++)    /*    row of matrix    */
  1238.             {
  1239.                 for(k = 0;k <= 3;k++)
  1240.                 {
  1241.                     newVect[j] += (**w_objs_hndl).bg_object[n].rotHist[j][k].rotElem * vector[k];
  1242.                 }
  1243.             }
  1244.             for(j = 0;j <= 3;j++)
  1245.             {
  1246.                 vector[j] = newVect[j];
  1247.             }
  1248.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point = ceil(vector[0]);
  1249.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point = ceil(vector[1]);
  1250.             (**w_objs_hndl).bg_object[n]._3dPt_BG[i].z_point = ceil(vector[2]);
  1251.         }
  1252.     }    
  1253.     /******************* end of update _3dPt[i] ********************/
  1254.  
  1255.     offset = (**w_objs_hndl).scrollAmount;
  1256.     //obj_rect = (**w_objs_hndl).object[index].bounds;
  1257.     //OffsetRect(&obj_rect, -offset.h, -offset.v);
  1258.                 
  1259.     //EraseRect(&obj_rect);
  1260.     //InvalRect(&obj_rect);
  1261.     
  1262.     /************************
  1263.     
  1264.     for(n = 0;n <= 15;n++)
  1265.     {
  1266.         minX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1267.         maxX = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1268.         minY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1269.         maxY = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1270.  
  1271.         limit = (**w_objs_hndl).bg_object[n].max_pts;
  1272.         
  1273.         for(i = 1; i < limit; i++)
  1274.         {
  1275.             tempX = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].x_point;
  1276.             tempY = (**w_objs_hndl).bg_object[n]._3dPt_BG[i].y_point;
  1277.             if(tempX < minX)
  1278.             {
  1279.                 minX = tempX;
  1280.             }
  1281.             if(tempX > maxX)
  1282.             {
  1283.                 maxX = tempX;
  1284.             }
  1285.             if(tempY < minY)
  1286.             {
  1287.                 minY = tempY;
  1288.             }
  1289.             if(tempY > maxY)
  1290.             {
  1291.                 maxY = tempY;
  1292.             }
  1293.         }
  1294.         SetRect(&(**w_objs_hndl).bg_object[n].bounds,minX,minY,maxX+1,maxY+1);
  1295.         //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  1296.         //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  1297.     }
  1298.     
  1299.     *****************/
  1300.     /*******************
  1301.     
  1302.     if((**w_objs_hndl).hasTargets == TRUE)
  1303.     {
  1304.         for(n = 16;n <= 21;n++)
  1305.         {
  1306.             _left = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].x_point;
  1307.             _top = (**w_objs_hndl).bg_object[n]._3dPt_BG[0].y_point;
  1308.             _right = _left + 32;
  1309.             _bottom = _top + 32;
  1310.             SetRect(&(**w_objs_hndl).bg_object[n].bounds,_left,_top,_right,_bottom);
  1311.             //InvalRect(&(**w_objs_hndl).bg_object[n].bounds);
  1312.             //EraseRect(&(**w_objs_hndl).bg_object[n].bounds);
  1313.         }
  1314.     }
  1315.     
  1316.     ********************/
  1317.     
  1318.     if(notFront)
  1319.     {
  1320.         SetPort(oldPort);
  1321.         notFront = FALSE;
  1322.     }
  1323.     
  1324.     /***************** experimental modification *****************/
  1325.     /*draw_object(wPtr,index);*/
  1326.     do_update(wPtr);
  1327.     /*do_spec_update(wPtr,index);*/
  1328.     /************** end of experimental modification *************/    
  1329. }
  1330.  
  1331.  
  1332. /*********************** MatrixTimesVector ***********************/
  1333. //void    MatrixTimesVector(mat,vect)
  1334. void    MatrixTimesVector(double_t    mat[4][4], double_t    *vect[])
  1335. {
  1336.     short    i,j;
  1337.     double_t    newVect[4];
  1338.     
  1339.     for(i = 0;i<=3;i++)
  1340.     {
  1341.         newVect[i] = 0;
  1342.     }
  1343.     for(i = 0;i <= 3;i++)    /*    row of matrix    */
  1344.     {
  1345.         for(j = 0;j <= 3;j++)
  1346.         {
  1347.             newVect[i] += mat[i][j] * *vect[j];
  1348.         }
  1349.     }
  1350.     for(i = 0;i<=3;i++)
  1351.     {
  1352.         *vect[i] = newVect[i];
  1353.     }
  1354. }
  1355. /******************** end of MatrixTimesVector *******************/
  1356.  
  1357. /**************************** SinCos *****************************/
  1358. void    GetSinCos(double_t delQ,double_t *sinQ,double_t *cosQ)
  1359. //double    delQ;
  1360. //double    *sinQ;
  1361. //double    *cosQ;
  1362. {
  1363.     double_t        temp,temp1,sinsqrd,dif;
  1364.     //extended    result,result1;
  1365.     double_t    result,result1;
  1366.  
  1367.     /************ sin ************/
  1368.     temp1 = (delQ/360) * 2 * 3.141592654;
  1369.     //x96tox80(&temp1,&result1);
  1370.     //result = sin(result1);                /* result is sin in extended format    */
  1371.     result = sin(temp1);                /* result is sin in extended format    */
  1372.     //x80tox96(&result,&temp);
  1373.     //*sinQ = temp;
  1374.     *sinQ = result;
  1375.  
  1376.     /************ cos ************/
  1377.     
  1378.     //sinsqrd = temp * temp;
  1379.     sinsqrd = result * result;
  1380.     dif = 1 - sinsqrd;
  1381.     //x96tox80(&dif,&result1);
  1382.     //result = sqrt(result1);
  1383.     result = sqrt(dif);
  1384.     //x80tox96(&result,&temp);
  1385.     //*cosQ = temp;
  1386.     *cosQ = result;
  1387.     
  1388. /*    temp1 = (delQ/360) * 2 * 3.141592654;*/
  1389. /*    x96tox80(&temp1,&result1);*/
  1390. /*    result = cos(result1);*/
  1391. /*    x80tox96(&result,&temp);*/
  1392. /*    *cosQ = temp;*/
  1393.     
  1394. }
  1395. /************************* end of SinCos *************************/
  1396.  
  1397. /************************** MatTimesMat **************************/
  1398. //void    MatTimesMat(rotMat,oRotMat,/*rRotMat*/qRotMat)
  1399. void    MatTimesMat(double_t    rotMat[4][4],double_t    oRotMat[4][4],/*rRotMat*/double_t    *qRotMat[])
  1400. //double    rotMat[4][4];
  1401. //double    oRotMat[4][4];
  1402. /*double    *rRotMat[4][4];*/
  1403. //double    *qRotMat[];
  1404. {
  1405.     short    i,j,k;
  1406.     double_t    rRotMat[4][4];
  1407.     double_t    tempRotArray[16];
  1408.     
  1409.     for(i = 0;i <= 3;i++)
  1410.     {
  1411.         for(j = 0;j <= 3;j++)
  1412.         {
  1413.             rRotMat[i][j] = 0;
  1414.         }
  1415.     }
  1416.     for(i = 0;i <= 3;i++)
  1417.     {
  1418.         for(j = 0;j <= 3;j++)
  1419.         {
  1420.             for(k = 0;k <= 3;k++)
  1421.             {
  1422.                 rRotMat[i][j] += rotMat[i][k] * oRotMat[k][j];    
  1423.             }
  1424.         }
  1425.     }
  1426.     /**************** temp soln to problem ***************************/
  1427.     for(i = 0;i <= 15;i++)
  1428.     {
  1429.         tempRotArray[i] = rRotMat[i%4][i/4]; 
  1430.     }
  1431.     for(i = 0;i <= 15;i++)
  1432.     {
  1433.         *qRotMat[i] = tempRotArray[i];
  1434.     }
  1435.     /************* end of temp soln to problem ***********************/
  1436. }
  1437.  
  1438. /*************************** FireGuns ****************************/
  1439. void    FireGuns(long *innerSel,long *outerSel)
  1440. {
  1441.     SndChannelPtr    Chan00,Chan01,Chan02,Chan03,Chan04,Chan05,Chan06,Chan07,Chan08,Chan09;
  1442.     long            init;
  1443.     short            i,synth = 5;
  1444.     OSErr            errCode,iErr;
  1445. /* cw5 */    //
  1446.     SndListHandle    guns00,guns01,guns02,guns03,guns04,guns05,guns06,guns07,guns08,guns09,missle,razz;
  1447.     Boolean            quietNow = 0;
  1448.     long            dummy,start,start1,stop1,start2,stop2,ET,ET1,ET2;
  1449.     WObjsHandle        w_objs_hndl;
  1450.     Point            thePt;
  1451.     short            n,mCount;
  1452.     WindowPtr        save_port;
  1453.     
  1454.     w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
  1455.     
  1456.     GetPort(&save_port);
  1457.     SetPort(lastPtr);
  1458.     
  1459.     n = 0;
  1460.     while((**w_objs_hndl).object[n].armed == FALSE) n++;
  1461.     
  1462.     switch((**w_objs_hndl).arms_selected)
  1463.     {
  1464.         case 0:
  1465.             Chan00 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1466.             if(Chan00 != nil)
  1467.             {
  1468.                 Chan00->qLength = stdQLength;
  1469.                 iErr = SndNewChannel(&Chan00,sampledSynth,initMono,nil);
  1470.             }
  1471.             Chan01 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1472.             if(Chan01 != nil)
  1473.             {
  1474.                 Chan01->qLength = stdQLength;
  1475.                 iErr = SndNewChannel(&Chan01,sampledSynth,initMono,nil);
  1476.             }
  1477.             Chan02 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1478.             if(Chan02 != nil)
  1479.             {
  1480.                 Chan02->qLength = stdQLength;
  1481.                 iErr = SndNewChannel(&Chan02,sampledSynth,initMono,nil);
  1482.             }
  1483.             Chan03 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1484.             if(Chan03 != nil)
  1485.             {
  1486.                 Chan03->qLength = stdQLength;
  1487.                 iErr = SndNewChannel(&Chan03,sampledSynth,initMono,nil);
  1488.             }
  1489.             Chan04 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1490.             if(Chan04 != nil)
  1491.             {
  1492.                 Chan04->qLength = stdQLength;
  1493.                 iErr = SndNewChannel(&Chan04,sampledSynth,initMono,nil);
  1494.             }
  1495.             Chan05 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1496.             if(Chan05 != nil)
  1497.             {
  1498.                 Chan05->qLength = stdQLength;
  1499.                 iErr = SndNewChannel(&Chan05,sampledSynth,initMono,nil);
  1500.             }
  1501.             Chan06 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1502.             if(Chan06 != nil)
  1503.             {
  1504.                 Chan06->qLength = stdQLength;
  1505.                 iErr = SndNewChannel(&Chan06,sampledSynth,initMono,nil);
  1506.             }
  1507.             Chan07 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1508.             if(Chan07 != nil)
  1509.             {
  1510.                 Chan07->qLength = stdQLength;
  1511.                 iErr = SndNewChannel(&Chan07,sampledSynth,initMono,nil);
  1512.             }
  1513.             Chan08 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1514.             if(Chan08 != nil)
  1515.             {
  1516.                 Chan08->qLength = stdQLength;
  1517.                 iErr = SndNewChannel(&Chan08,sampledSynth,initMono,nil);
  1518.             }
  1519.             Chan09 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1520.             if(Chan09 != nil)
  1521.             {
  1522.                 Chan09->qLength = stdQLength;
  1523.                 iErr = SndNewChannel(&Chan09,sampledSynth,initMono,nil);
  1524.             }
  1525.     /************************/
  1526. /* cw5 */    //guns00 = GetResource ('snd ', 1200);
  1527.     
  1528.             //if (guns00 != NULL)
  1529.             //{
  1530.             //    Delay(0L,&start);
  1531.             //    for(i = 0;i <=9;i++)
  1532.             //    {
  1533.             //        errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan00, guns00, true);        //errCode = SndPlay (NULL, guns0, false);
  1534.             //        Delay(3L,&dummy);
  1535.             //    }
  1536.         /******************************/
  1537.                 
  1538.             //    errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan01, guns00, true);    /*    true means asynchronous    */
  1539.         /******************************
  1540.                 Delay(10L,&dummy);
  1541.             
  1542.                 errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[i].Chan02, guns00, true);
  1543.                 Delay(3L,&dummy);
  1544.             
  1545.                 errCode = SndPlay (Chan03, guns00, true);
  1546.                 Delay(3L,&dummy);
  1547.             
  1548.                 errCode = SndPlay (Chan04, guns00, true);
  1549.                 Delay(3L,&dummy);
  1550.             
  1551.                 errCode = SndPlay (Chan05, guns00, true);
  1552.                 Delay(3L,&dummy);
  1553.             
  1554.                 errCode = SndPlay (Chan06, guns00, true);
  1555.                 Delay(3L,&dummy);
  1556.             
  1557.                 errCode = SndPlay (Chan07, guns00, true);
  1558.                 Delay(3L,&dummy);
  1559.             
  1560.                 errCode = SndPlay (Chan08, guns00, true);
  1561.                 Delay(3L,&dummy);
  1562.             
  1563.                 errCode = SndPlay (Chan09, guns00, true);
  1564.                 Delay(3L,&dummy);
  1565.         ****************************************************/
  1566.                 //Delay(0L,&stop);
  1567.                 //ET = stop - start;
  1568.                 //ET1 = stop1 - start1;
  1569.                 //ET2 = stop2 - start2;
  1570.             //}
  1571.         /***************************************************    
  1572.             iErr = SndDisposeChannel(Chan01,quietNow);
  1573.             iErr = SndDisposeChannel(Chan02,quietNow);
  1574.             iErr = SndDisposeChannel(Chan03,quietNow);
  1575.             iErr = SndDisposeChannel(Chan04,quietNow);
  1576.             iErr = SndDisposeChannel(Chan05,quietNow);
  1577.             iErr = SndDisposeChannel(Chan06,quietNow);
  1578.             iErr = SndDisposeChannel(Chan07,quietNow);
  1579.             iErr = SndDisposeChannel(Chan08,quietNow);
  1580.             iErr = SndDisposeChannel(Chan09,quietNow);
  1581.         ****************************************************/
  1582.             SetPt(&thePt,(**w_objs_hndl).object[n]._3dPtH[7].x_point,(**w_objs_hndl).object[n]._3dPtH[7].y_point);
  1583.             if    (
  1584.                     PtInRect(thePt,&gFirstCalcIcon) &&
  1585.                     (**w_objs_hndl).bg_object[16].alive &&
  1586.                     (**w_objs_hndl).bg_object[16]._3dPt_BG[0].z_point < 0
  1587.                 )
  1588.             {
  1589.                 EraseRect(&gFirstCalcIcon);
  1590.                 InvalRect(&lastPtr->portRect);
  1591.                 InvalRect(&gFirstCalcIcon);
  1592.                 (**w_objs_hndl).bg_object[16].alive = FALSE;
  1593.                 (**w_objs_hndl).targets_left -= 1;
  1594.                 //draw_palette(lastPtr);
  1595.                 do_update(lastPtr);
  1596.             }
  1597.             if    (
  1598.                     PtInRect(thePt,&gSecondCalcIcon) &&
  1599.                     (**w_objs_hndl).bg_object[17].alive &&
  1600.                     (**w_objs_hndl).bg_object[17]._3dPt_BG[0].z_point < 0
  1601.                 )
  1602.             {
  1603.                 EraseRect(&gSecondCalcIcon);
  1604.                 InvalRect(&lastPtr->portRect);
  1605.                 InvalRect(&gSecondCalcIcon);
  1606.                 (**w_objs_hndl).bg_object[17].alive = FALSE;
  1607.                 (**w_objs_hndl).targets_left -= 1;
  1608.                 //draw_palette(lastPtr);
  1609.                 do_update(lastPtr);
  1610.             }
  1611.             if    (
  1612.                     PtInRect(thePt,&gThirdCalcIcon) &&
  1613.                     (**w_objs_hndl).bg_object[18].alive &&
  1614.                     (**w_objs_hndl).bg_object[18]._3dPt_BG[0].z_point < 0
  1615.                 )
  1616.             {
  1617.                 EraseRect(&gThirdCalcIcon);
  1618.                 InvalRect(&gThirdCalcIcon);
  1619.                 InvalRect(&lastPtr->portRect);
  1620.                 (**w_objs_hndl).bg_object[18].alive = FALSE;
  1621.                 (**w_objs_hndl).targets_left -= 1;
  1622.                 //draw_palette(lastPtr);
  1623.                 do_update(lastPtr);
  1624.             }
  1625.             if    (
  1626.                     PtInRect(thePt,&gFourthCalcIcon) &&
  1627.                     (**w_objs_hndl).bg_object[19].alive &&
  1628.                     (**w_objs_hndl).bg_object[19]._3dPt_BG[0].z_point < 0
  1629.                 )
  1630.             {
  1631.                 EraseRect(&gFourthCalcIcon);
  1632.                 InvalRect(&gFourthCalcIcon);
  1633.                 InvalRect(&lastPtr->portRect);
  1634.                 (**w_objs_hndl).bg_object[19].alive = FALSE;
  1635.                 (**w_objs_hndl).targets_left -= 1;
  1636.                 //draw_palette(lastPtr);
  1637.                 do_update(lastPtr);
  1638.             }
  1639.             if    (
  1640.                     PtInRect(thePt,&gFifthCalcIcon) &&
  1641.                     (**w_objs_hndl).bg_object[20].alive &&
  1642.                     (**w_objs_hndl).bg_object[20]._3dPt_BG[0].z_point < 0
  1643.                 )
  1644.             {
  1645.                 EraseRect(&gFifthCalcIcon);
  1646.                 InvalRect(&gFifthCalcIcon);
  1647.                 InvalRect(&lastPtr->portRect);
  1648.                 (**w_objs_hndl).bg_object[20].alive = FALSE;
  1649.                 (**w_objs_hndl).targets_left -= 1;
  1650.                 do_update(lastPtr);
  1651.                 //draw_palette(lastPtr);
  1652.             }
  1653.             if    (
  1654.                     PtInRect(thePt,&gSixthCalcIcon) &&
  1655.                     (**w_objs_hndl).bg_object[21].alive &&
  1656.                     (**w_objs_hndl).bg_object[21]._3dPt_BG[0].z_point < 0
  1657.                 )
  1658.             {
  1659.                 /*EraseRect(&gSixthCalcIcon);
  1660.                 InvalRect(&gSixthCalcIcon);
  1661.                 (**w_objs_hndl).bg_object[21].alive = FALSE;
  1662.                 (**w_objs_hndl).targets_left -= 1;*/
  1663.                 //draw_palette(lastPtr);
  1664. /* cw5 */        //razz = GetResource ('snd ', 403);
  1665.                 //if (razz != NULL)
  1666.                 //{
  1667.                 //    errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[0].Chan00, razz, true);        //errCode = SndPlay (NULL, guns0, false);
  1668.                 //}    
  1669.                 //do_update(lastPtr);
  1670.             }
  1671.             //iErr = SndDisposeChannel(Chan00,quietNow);
  1672.             break;
  1673.         case 1:
  1674.             mCount = (**w_objs_hndl).object[n].missles;
  1675.             if(mCount > 0)
  1676.             {
  1677.                 //Chan00 = (SndChannelPtr)NewPtrClear(sizeof(SndChannel));
  1678.                 //if(Chan00 != nil)
  1679.                 //{
  1680.                 //    Chan00->qLength = stdQLength;
  1681.                 //    iErr = SndNewChannel(&Chan00,sampledSynth,initMono,nil);
  1682.                 //}
  1683. /* cw5 */        //missle = GetResource ('snd ', 1300);
  1684.                 //if (missle != NULL)
  1685.                 //{
  1686.                 //    errCode = SndPlay ((**w_objs_hndl).object[n].sndStruct[1].Chan00, missle, true);        //errCode = SndPlay (NULL, guns0, false);
  1687.                 //}
  1688.                 (**w_objs_hndl).object[n].missles -= 1;
  1689.                 EraseRect(&(**w_objs_hndl).object[n].mStruct[14 - mCount].mRect);
  1690.                 InvalRect(&(**w_objs_hndl).object[n].mStruct[14 - mCount].mRect);
  1691.                 do_update(lastPtr);
  1692.                 //iErr = SndDisposeChannel(Chan00,quietNow);     
  1693.                 GuideMissle(innerSel,outerSel);
  1694.             }
  1695.             //TrackTarget();
  1696.             break;
  1697.         case 2:
  1698.             DarkWindowInit();
  1699.             break;
  1700.     }
  1701.     SetPort(save_port);
  1702. }
  1703. /*********************** end of FireGuns *************************/
  1704.  
  1705.  
  1706. /************************* TrackTarget ***************************/
  1707. Boolean    TrackTarget(long *innerSel,long *outerSel)
  1708. {
  1709.     WObjsHandle        w_objs_hndl;
  1710.     short            i,n;
  1711.     long            calcX,calcY,calcZ,hseX,hseY;
  1712.     long            delX,delY,delZ;
  1713.     double_t        radius,hyp;
  1714.  
  1715.     w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
  1716.     n = 0;
  1717.     while((**w_objs_hndl).object[n].armed == FALSE) n++;
  1718.     if((**w_objs_hndl).hasTargets == TRUE)
  1719.     {
  1720.         hseX = (**w_objs_hndl).object[n]._3dPtH[7].x_point;
  1721.         hseY = (**w_objs_hndl).object[n]._3dPtH[7].y_point;
  1722.         for(i = 0;i <=5;i++)
  1723.         {
  1724.             if((**w_objs_hndl).bg_object[i+16].alive)
  1725.             {
  1726.                 calcZ = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].z_point;
  1727.                 if(calcZ < 0)
  1728.                 {
  1729.                     calcX = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].x_point + 16;
  1730.                     calcY = (**w_objs_hndl).bg_object[i+16]._3dPt_BG[0].y_point + 16;
  1731.                     delX = hseX - calcX;            /* X dif of target & hse crosshairs */
  1732.                     if(delX < 0) delX *= -1;
  1733.                     delY = hseY - calcY;            /* Y dif of target & hse crosshairs */
  1734.                     if(delY < 0) delY *= -1;
  1735.                     calcZ *= -1;
  1736.                     radius = sqrt(delX*delX + delY*delY); /* radius is in plane of screen    */
  1737.                     hyp = radius/(double_t)calcZ;            /* hyp is really Tan(œ)    */
  1738.                     if(hyp <= .5)                            /* if angle <= 26.5 degress    */
  1739.                     {
  1740.                         if(hyp <= .25)    switch(i)            /* if angle <= 14 degress    */
  1741.                         {
  1742.                             case 0:
  1743.                                 *innerSel |= 0x00000001;
  1744.                                 break;
  1745.                             case 1:
  1746.                                 *innerSel |= 0x00000010;
  1747.                                 break;
  1748.                             case 2:
  1749.                                 *innerSel |= 0x00000100;
  1750.                                 break;
  1751.                             case 3:
  1752.                                 *innerSel |= 0x00001000;
  1753.                                 break;
  1754.                             case 4:
  1755.                                 *innerSel |= 0x00010000;
  1756.                                 break;
  1757.                             case 5:
  1758.                                 *innerSel |= 0x00100000;
  1759.                                 break;
  1760.                         }
  1761.                         else switch(i)
  1762.                         {
  1763.                             case 0:
  1764.                                 *outerSel |= 0x00000001;
  1765.                                 break;
  1766.                             case 1:
  1767.                                 *outerSel |= 0x00000010;
  1768.                                 break;
  1769.                             case 2:
  1770.                                 *outerSel |= 0x00000100;
  1771.                                 break;
  1772.                             case 3:
  1773.                                 *outerSel |= 0x00001000;
  1774.                                 break;
  1775.                             case 4:
  1776.                                 *outerSel |= 0x00010000;
  1777.                                 break;
  1778.                             case 5:
  1779.                                 *outerSel |= 0x00100000;
  1780.                                 break;
  1781.                         }
  1782.                     }
  1783.                 }
  1784.             }
  1785.         }
  1786.     }
  1787. }
  1788. /********************** end of TrackTarget ***********************/
  1789.  
  1790. /************************** GuideMissle **************************/
  1791. void GuideMissle(long *innerSel,long *outerSel)
  1792. {
  1793.     WObjsHandle    w_objs_hndl;
  1794.     long        z1 = -5000;
  1795.     long        z2 = -5000;
  1796.     long        z3 = -5000;
  1797.     long        z4 = -5000;
  1798.     long        z5 = -5000;
  1799.     long        z6 = -5000;
  1800.     long        Tx,Ty,Tz;
  1801.     long        selected;
  1802.     Boolean        notDone = true;
  1803.     Boolean        notYetDone = false;
  1804.     Boolean        notHit,notOutOfRange;
  1805.     short        mCount,n,pCount;
  1806.     PicHandle    f1Missle,f2Missle,f3Missle,f4Missle,f5Missle,f6Missle;
  1807.     long        dummy;
  1808.     
  1809.     w_objs_hndl = (WObjsHandle)GetWRefCon(lastPtr);
  1810.     n = 0;
  1811.     while((**w_objs_hndl).object[n].armed == FALSE) n++;
  1812.     
  1813.     if(*innerSel & 0x00000001)
  1814.     {
  1815.         z1 = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].z_point;
  1816.     }
  1817.     if(*innerSel & 0x00000010)
  1818.     {
  1819.         z2 = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].z_point;
  1820.     }
  1821.     if(*innerSel & 0x00000100)
  1822.     {
  1823.         z3 = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].z_point;
  1824.     }
  1825.     if(*innerSel & 0x00001000)
  1826.     {
  1827.         z4 = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].z_point;
  1828.     }
  1829.     if(*innerSel & 0x00010000)
  1830.     {
  1831.         z5 = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].z_point;
  1832.     }
  1833.     if(*innerSel & 0x00100000)
  1834.     {
  1835.         z6 = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].z_point;
  1836.     }
  1837.     selected = z1;
  1838.     if(z2 > selected) selected = z2;
  1839.     if(z3 > selected) selected = z3;
  1840.     if(z4 > selected) selected = z4;    
  1841.     if(z5 > selected) selected = z5;    
  1842.     if(z6 > selected) selected = z6;    
  1843.     
  1844.     if(selected == z1)
  1845.     {
  1846.         Tx = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].x_point;
  1847.         Ty = (**w_objs_hndl).bg_object[16]._3dPt_BG[0].y_point;
  1848.         Tz = z1;
  1849.     }
  1850.     if(selected == z2)
  1851.     {
  1852.         Tx = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].x_point;
  1853.         Ty = (**w_objs_hndl).bg_object[17]._3dPt_BG[0].y_point;
  1854.         Tz = z2;
  1855.     }
  1856.     if(selected == z3)
  1857.     {
  1858.         Tx = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].x_point;
  1859.         Ty = (**w_objs_hndl).bg_object[18]._3dPt_BG[0].y_point;
  1860.         Tz = z3;
  1861.     }
  1862.     if(selected == z4)
  1863.     {
  1864.         Tx = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].x_point;
  1865.         Ty = (**w_objs_hndl).bg_object[19]._3dPt_BG[0].y_point;
  1866.         Tz = z4;
  1867.     }
  1868.     if(selected == z5)
  1869.     {
  1870.         Tx = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].x_point;
  1871.         Ty = (**w_objs_hndl).bg_object[20]._3dPt_BG[0].y_point;
  1872.         Tz = z5;
  1873.     }
  1874.     if(selected == z6)
  1875.     {
  1876.         Tx = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].x_point;
  1877.         Ty = (**w_objs_hndl).bg_object[21]._3dPt_BG[0].y_point;
  1878.         Tz = z6;
  1879.     }
  1880.     
  1881.     f1Missle = GetPicture( 131 );
  1882.     f2Missle = GetPicture( 132 );
  1883.     f3Missle = GetPicture( 129 );    
  1884.     f4Missle = GetPicture( 133 );    
  1885.     f5Missle = GetPicture( 134 );    
  1886.     f6Missle = GetPicture( 135 );    
  1887.     mCount = (**w_objs_hndl).object[n].missles;
  1888.     if(f2Missle != 0)
  1889.     {
  1890.         switch(13 - mCount)
  1891.         {
  1892.             case 0:
  1893.             case 2:
  1894.             case 4:
  1895.             case 6:
  1896.                 SetRect    (
  1897.                             &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1898.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left-5,
  1899.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1900.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right-5,
  1901.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1902.                         );
  1903.                 break;
  1904.             case 1:
  1905.             case 3:
  1906.             case 5:
  1907.             case 7:
  1908.                 SetRect    (
  1909.                             &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1910.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left+5,
  1911.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1912.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right+5,
  1913.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1914.                         );
  1915.                 break;
  1916.             case 8:
  1917.             case 9:
  1918.             case 10:
  1919.             case 11:
  1920.             case 12:
  1921.             case 13:
  1922.                 SetRect    (
  1923.                             &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1924.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left,
  1925.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1926.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right,
  1927.                             (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1928.                         );
  1929.                 break;            
  1930.         }
  1931.         DrawPicture(f2Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  1932.         Delay(10,&dummy);
  1933.         EraseRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  1934.         //do_update(lastPtr);
  1935.         if(f1Missle != 0)
  1936.         {
  1937.             switch(13 - mCount)
  1938.             {
  1939.                 case 0:
  1940.                 case 2:
  1941.                 case 4:
  1942.                 case 6:
  1943.                     SetRect    (
  1944.                                 &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1945.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left-5,
  1946.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1947.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right-5,
  1948.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1949.                             );
  1950.                     break;
  1951.                 case 1:
  1952.                 case 3:
  1953.                 case 5:
  1954.                 case 7:
  1955.                     SetRect    (
  1956.                                 &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1957.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left+5,
  1958.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1959.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right+5,
  1960.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1961.                             );
  1962.                     break;
  1963.                 case 8:
  1964.                 case 9:
  1965.                 case 10:
  1966.                 case 11:
  1967.                 case 12:
  1968.                 case 13:
  1969.                     SetRect    (
  1970.                                 &(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,
  1971.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.left,
  1972.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.top+5,
  1973.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.right,
  1974.                                 (**w_objs_hndl).object[n].mStruct[13 - mCount].mRect.bottom+5
  1975.                             );
  1976.                     break;            
  1977.             }
  1978.         }
  1979.         
  1980.         switch(13 - mCount)
  1981.         {
  1982.             case 0:
  1983.             case 1:
  1984.             case 2:
  1985.             case 3:
  1986.             case 4:
  1987.             case 5:
  1988.             case 6:
  1989.             case 7:
  1990.                 //InsetRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect,-2,-2);
  1991.                 DrawPicture(f1Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  1992.                 break;
  1993.             case 8:
  1994.                 DrawPicture(f3Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  1995.                 break;
  1996.             case 9:
  1997.                 DrawPicture(f4Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  1998.                 break;
  1999.             case 10:
  2000.                 DrawPicture(f5Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  2001.                 break;
  2002.             case 11:
  2003.                 DrawPicture(f6Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  2004.                 break;
  2005.             case 12:
  2006.                 DrawPicture(f3Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  2007.                 break;
  2008.             case 13:
  2009.                 DrawPicture(f4Missle,&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  2010.                 break;
  2011.         }
  2012.         //do_update(lastPtr);
  2013.         Delay(10,&dummy);
  2014.         EraseRect(&(**w_objs_hndl).object[n].mStruct[13 - mCount].mRect);
  2015.         do_update(lastPtr);
  2016.         notHit = TRUE;
  2017.         notOutOfRange = TRUE;
  2018.         while(notHit || notOutOfRange)
  2019.         {
  2020.             /*    loop        */
  2021.                 
  2022.                 /*    calculate dx,dy,dz    */
  2023.                 /*    SetRect()            */
  2024.                 /*    DrawPicture()        */
  2025.                 /*    EraseRect()            */
  2026.                 
  2027.             /*    end loop    */
  2028.             notOutOfRange = FALSE;
  2029.             notHit = FALSE;
  2030.             
  2031.         }
  2032.     }
  2033. }
  2034. /********************** end of GuideMissle ***********************/
  2035.